package cn.skyquant.quant4j.service.boot.web.interceptor;

import cn.skyquant.quant4j.api.dto.ResultDTO;
import cn.skyquant.quant4j.sdk.util.log.LogUtil;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Throwable.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ResponseBody
    public ResultDTO handleSQLException(HttpServletRequest request, Throwable ex) {
        LogUtil.error(request.getRequestURI(),ex);
        return ResultDTO.error(ex.getMessage());
    }
}
